#ifndef	_AHO_CONST_H_
#define	_AHO_CONST_H_

#define ASSERT
#ifdef ASSERT
void assertion_failure(char *exp, char *file,char *base_file, int line);
#define assert(exp) if (exp) ; \
    else assertion_failure(#exp, __FILE__, __BASE_FILE__, __LINE__)
#else
#define assert(exp)
#endif

/* GDT 和 IDT 中描述符的个数 */
#define	GDT_SIZE	128
#define	IDT_SIZE	256

#define LDT_SIZE		2


/* Gdt Index */
#define	INDEX_DUMMY		    0
#define	INDEX_FLAT_C		1
#define	INDEX_FLAT_RW		2
#define	INDEX_VIDEO         3
#define	INDEX_TSS           4
#define	INDEX_LDT_FIRST		5
/* 段选择子 */
#define SELECTOR_DUMPY      0x00
#define SELECTOR_FLATC      0x08
#define SELECTOR_FLATRW     0x10
#define SELECTOR_VIDEO      (0x18+3)
#define	SELECTOR_TSS		0x20
#define SELECTOR_LDT_FIRST	0x28
#define INDEX_LDT_RW            1
//中断控制器的端口

//主中断控制器
#define INT_M_CTL     0x20
#define INT_M_CTLMASK 0x21 
//从中断控制器
#define INT_S_CTL     0xA0 
#define INT_S_CTLMASK 0xA1

/* 权限 */
#define	PRIVILEGE_KRNL	0
#define	PRIVILEGE_TASK	1
#define	PRIVILEGE_USER	3

//中断向量
#define	INT_VECTOR_IRQ0			0x20
#define	INT_VECTOR_IRQ8			0x28


/* 描述符类型值说明 */
#define	DA_32			0x4000	/* 32 位段				*/
#define	DA_LIMIT_4K		0x8000	/* 段界限粒度为 4K 字节			*/
#define	DA_DPL0			0x00	/* DPL = 0				*/
#define	DA_DPL1			0x20	/* DPL = 1				*/
#define	DA_DPL2			0x40	/* DPL = 2				*/
#define	DA_DPL3			0x60	/* DPL = 3				*/
/* 存储段描述符类型值说明 */
#define	DA_DR			0x90	/* 存在的只读数据段类型值		*/
#define	DA_DRW			0x92	/* 存在的可读写数据段属性值		*/
#define	DA_DRWA			0x93	/* 存在的已访问可读写数据段类型值	*/
#define	DA_C			0x98	/* 存在的只执行代码段属性值		*/
#define	DA_CR			0x9A	/* 存在的可执行可读代码段属性值		*/
#define	DA_CCO			0x9C	/* 存在的只执行一致代码段属性值		*/
#define	DA_CCOR			0x9E	/* 存在的可执行可读一致代码段属性值	*/
/* 系统段描述符类型值说明 */
#define	DA_LDT			0x82	/* 局部描述符表段类型值			*/
#define	DA_TaskGate		0x85	/* 任务门类型值				*/
#define	DA_386TSS		0x89	/* 可用 386 任务状态段类型值		*/
#define	DA_386CGate		0x8C	/* 386 调用门类型值			*/
#define	DA_386IGate		0x8E	/* 386 中断门类型值			*/
#define	DA_386TGate		0x8F

#define	SA_RPL_MASK	0xFFFC
#define	SA_RPL0		0
#define	SA_RPL1		1
#define	SA_RPL2		2
#define	SA_RPL3		3

#define	SA_TI_MASK	0xFFFB
#define	SA_TIG		0
#define	SA_TIL		4

/* RPL */
#define	RPL_KRNL	SA_RPL0
#define	RPL_TASK	SA_RPL1
#define	RPL_USER	SA_RPL3

//系统调用数量
#define NR_SYS_CALL 256

/* 8253  */
#define TIMER0                0x40  //时钟0端口
#define TIMER_MODE            0x43  //时钟模式端口
#define RATE_GENERATE         0x34  //时钟模式
#define TIMER_FREQ        1193182L  //时钟频率
#define HZ                     100  //设定的时钟频率

enum msgtype {
	/* 
	 * when hard interrupt occurs, a msg (with type==HARD_INT) will
	 * be sent to some tasks
	 */
	HARD_INT = 1,

	/* SYS task */
	GET_TICKS,
};

//控制台数量
#define NR_CONSOLES 3

#define MAG_CH_PANIC	'\002' //魔术字
#define MAG_CH_ASSERT	'\003'

#define SENDING   0x02	/* set when proc trying to send */
#define RECEIVING 0x04
#define ANY		(NR_TASKS + NR_PROC + 10)
#define NO_TASK		(NR_TASKS + NR_PROC + 20)
#define INTERRUPT	-10
/* IPC */
#define SEND		1
#define RECEIVE		2
#define BOTH		3
#define	RETVAL		u.m3.m3i1
#define TASK_SYS	1

/* 硬盘中断 */
#define	CASCADE_IRQ	2	/* cascade enable for 2nd AT controller */
#define	AT_WINI_IRQ	14	/* at winchester */

#define	MAX_DRIVES		2
#define	NR_PART_PER_DRIVE	4
#define	NR_SUB_PER_PART		16
#define	NR_SUB_PER_DRIVE	(NR_SUB_PER_PART * NR_PART_PER_DRIVE)
#define	NR_PRIM_PER_DRIVE	(NR_PART_PER_DRIVE + 1)
/* Hard Drive */
#define TASK_HD			2
#define SECTOR_SIZE		512
#define SECTOR_BITS		(SECTOR_SIZE * 8)
#define SECTOR_SIZE_SHIFT	9

#endif /* _AHO_CONST_H_ */